package com.dk.common.distribute.lock;

import lombok.RequiredArgsConstructor;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;

/**
 * 委托实现 分布式锁
 */
@RequiredArgsConstructor
public class DelegatingLock implements DistLock {
    private final Lock delegating;


    @Override
    public void lock() {
        delegating.lock();
    }

    @Override
    public void lockInterruptibly() throws InterruptedException {
        delegating.lockInterruptibly();
    }

    @Override
    public boolean tryLock() {
        return delegating.tryLock();
    }

    @Override
    public boolean tryLock(long time, TimeUnit unit) throws InterruptedException {
        return delegating.tryLock(time, unit);
    }

    @Override
    public void unlock() {
        delegating.unlock();
    }

    @Override
    public Condition newCondition() {
        return delegating.newCondition();
    }
}
